<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\Http\Requests\Checkpwd;

class IndexController extends CommonController
{

    /*后台首页*/
    public function index()
    {
        return view('admin.index.index');
    }


    /*重置密码视图*/
    public function rpwdview()
    {
        return view('admin.index.rpwdview');
    }

    /*确认重置密码*/
    public function rpwdpost(Checkpwd $request)
    {
        $validated = $request->validated();
        $adminM = Auth::user();
        $adminM->password = bcrypt($validated['newpwd']);
        if ($adminM->save()) {
            Auth::logout();
            return redirect('admin/login')->with('status', '修改成功，请重新登录');
        }
    }


    /*异步上传文件*/
    public function uploadfile(Request $request)
    {
        $filePathPre = 'upload/';
        $pathDate = date('Y-m-d');
        //图片上传处理
        $listImg = $request->file('file');
        if ($listImg) {
            $path = $listImg->store($pathDate);
            $filePath['data'] = $filePathPre . $path;
        }
        return $filePath;
    }


}
